using System;
using System.Data;
using System.Windows.Forms;
//using istComponents;
using istIUniDB;
using Shraga.BLL;

namespace Shraga.Client
{
	/// <summary>
	/// Summary description for DBclient.
	/// </summary>
	public class ShowNodeCandidateThread
	{
		private DataTable tblFindCandidate = null;
		private int m_PathID;
		private int m_Node_Id;
		private int m_Node_In_Path_ID;
		private string m_Field_ID_Select_List;

		public delegate void ShowNodeFinishedEventHandler(ShowNodeCandidateThread ThisThread);
		public event ShowNodeFinishedEventHandler Finished;

		public ShowNodeCandidateThread(int PathID, int Node_Id, int Node_In_Path_ID, string Field_ID_Select_List)
		{
			m_PathID = PathID;
			m_Node_Id = Node_Id;
			m_Node_In_Path_ID = Node_In_Path_ID;
			m_Field_ID_Select_List = Field_ID_Select_List;
		}

		public void Show()
		{
			ShowNodeCandidateToTable();
			if (Finished != null)
				Finished(this);

		}

		/// <summary>
		/// return DataTable of matches candidate
		/// </summary>
		private void ShowNodeCandidateToTable()
		{
			try
			{
				//Parameter Pernum
				clsParameter[] arrParam = new clsParameter[4];
				arrParam[0] = new clsParameter();
				arrParam[0].bByRef = false;
				arrParam[0].paramType = OracleTypes.Decimal;
				arrParam[0].Value = m_Node_Id;

				arrParam[1] = new clsParameter();
				arrParam[1].bByRef = false;
				arrParam[1].paramType = OracleTypes.Decimal;
				arrParam[1].Value = m_Node_In_Path_ID;

				arrParam[2] = new clsParameter();
				arrParam[2].bByRef = false;
				arrParam[2].paramType = OracleTypes.Decimal;
				arrParam[2].Value = m_PathID;

				arrParam[3] = new clsParameter();
				arrParam[3].bByRef = false;
				arrParam[3].paramType = OracleTypes.Varchar2;
				arrParam[3].Value = m_Field_ID_Select_List;

				//pNode_Id number, pNode_In_Path_ID number, pPathID number, pField_ID_Select_List varchar2)			
				tblFindCandidate = UniDBSingleton.Instance().UniDB.RunStoredFunctionReturnDataTable("Shraga_Node.Node_List",ref arrParam);
			}
			catch{
				tblFindCandidate = new DataTable();
			}
		}

		public DataTable DataSource
		{
			get	{return this.tblFindCandidate;}
		}
	}
}
